// pages/staff/my.js
const app = getApp();
var CONFIG = require("../../config/config.js");
var share = require('../../utils/share.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tel: '',
    userInfo: '',
    tuifalse: false,
    is_show:1,
  },


  // 点击选课记录
  studentchoose:function(){
    wx.redirectTo({
      url: '../public/userCourses?user_id='+app.globalData.uid+'',
    })
  },

  studentmyclass(){
    wx.redirectTo({
      url: '../student/myclass/myclass',
    })
  },


  // 点击退出登录
  tuiclick: function () {
    this.setData({
      tuifalse: true
    })
  },
  // 点击退出登录  取消
  noclick: function () {
    this.setData({
      tuifalse: false
    })
  },

  onHide: function () {
    this.setData({
      tuifalse: false
    })
  },

  // 点击退出登录  确定
  yesclick: function () {
    this.setData({
      tuifalse: false
    })
    wx.clearStorageSync();
      wx.showToast({
          title: '退出登录成功',
          icon: 'none',
          duration: 1500
      })
      setTimeout(function () {
          wx.redirectTo({
              url: '/pages/loginfirst',
          })
      }, 300)
  },


/**
 * 生命周期函数--监听页面加载
 */
onLoad: function (options) {
    var that = this;
    that.setData({
        userInfo: app.globalData.userInfo
    })
    var tel = wx.getStorageSync('tel');
    that.setData({
        tel: tel.replace(tel.substr(3, 4), "****")
    })
    share.wxRequest('crmapi/User/shopInfo', {}, function (res) {
        if (Number(res.data.errcode) == 0) {
            var is_show = res.data.data.is_show;
            that.setData({
                is_show: is_show,
            })
        }
    })

},


    /**
     * 生命周期函数--监听页面加载
     */
    onShow: function () {
        // console.log(app.globalData.userInfo);
        var that = this;
        that.setData({
            userInfo: app.globalData.userInfo
        })
        wx.getStorage({
            key: 'tel',
            success: function (res) {
                // console.log(res.data);
                var tel = res.data;
                that.setData({
                    tel: tel.replace(tel.substr(3, 4), "****")
                })
            },
            fail: function (res) {
                // console.log(898)
                that.setData({
                    tel: '',
                })
                wx.redirectTo({
                    url: '/pages/loginfirst',
                })
            }
        });
    },

  // 点击登录
  loginclick: function () {
    wx.navigateTo({
      url: '../login',
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: CONFIG.SHARETITLE,
      path: CONFIG.PATHLOGIN
    }
  }
})